package com.baymax.study.base.domain.entities;

import com.baymax.study.base.domain.listener.BaseEntityListener;
import lombok.Data;
import org.hibernate.annotations.GenericGenerator;

import javax.persistence.Column;
import javax.persistence.EntityListeners;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import javax.persistence.Version;
import java.util.Date;

/**
 * BaseEntity
 *
 * @author Baymax
 * @since 2024-07-22
 */
@Data
@MappedSuperclass
@EntityListeners(BaseEntityListener.class)
public abstract class BaseEntity {
    @Id
    @GeneratedValue(generator = "sys_uid")
    @GenericGenerator(name = "sys_uid", strategy = "uuid")
    @Column(name = "id", columnDefinition = "VARCHAR(64) COMMENT '主键'")
    private String id;

    @Column(name = "create_account", columnDefinition = "varchar(64) comment '创建人'", length = 64)
    private String createAccount;

    @Column(name = "create_date", columnDefinition = "datetime comment '创建时间'")
    private Date createDate;

    @Column(name = "last_update_account", columnDefinition = "varchar(64) comment '最后更新人'", length = 64)
    private String lastUpdateAccount;

    @Column(name = "last_update_date", columnDefinition = "datetime comment '最后更新时间'")
    private Date lastUpdateDate;

    @Version
    @Column(name = "version", columnDefinition = "bigint(20) comment '版本号'")
    private long version;

    public Date getCreateDate() {
        return createDate == null ? null : (Date) createDate.clone();
    }

    public void setCreateDate(Date createDate) {
        this.createDate = createDate == null ? null : (Date) createDate.clone();
    }

    public Date getLastUpdateDate() {
        return lastUpdateDate == null ? null : (Date) lastUpdateDate.clone();
    }

    public void setLastUpdateDate(Date lastUpdateDate) {
        this.lastUpdateDate = lastUpdateDate == null ? null : (Date) lastUpdateDate.clone();
    }
}
